/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.stock;

import entities.StockDetail;
import java.util.ArrayList;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

/**
 *
 * @author VietLH
 */
public class StockComboBoxModel implements ComboBoxModel{
    private ArrayList<StockDetail> stockList;
    private ArrayList<String> stockNameArray;
    private String selection;

    public StockComboBoxModel(ArrayList<StockDetail> stockList) {
        this.stockList=new ArrayList<StockDetail>();
        this.stockNameArray=new ArrayList<String>();
        this.stockList = stockList;
        for (StockDetail stockDetail : stockList) {
            stockNameArray.add(stockDetail.getsName());
        }
    }
    
    
    @Override
    public void setSelectedItem(Object anItem) {
        selection= (String)anItem;
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object getSelectedItem() {
        return selection;
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getSize() {
        return stockNameArray.size();
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object getElementAt(int index) {
        return stockNameArray.get(index);
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addListDataListener(ListDataListener l) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeListDataListener(ListDataListener l) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
